const { productsModel } = require('../models/productsModels');
const claimsModel = require('../models/classifysModels')
//获取保险数据
module.exports.getProducts = async function ({ pageSize, currentPage }) {
    // const data = await productsModel.find();
    // return data
    //总条数 数据
    const total = await productsModel.countDocuments({ delete: false });
    //总页数
    const pageCount = Math.ceil(total / pageSize);
    const data = await productsModel
        .find({ delete: false })
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize)
        .populate(
            {
                path: 'belongToClassifys',
            }
        );
    return { total, pageCount, data };
}
//删除某个保险数据 by_id
module.exports.deleteProducts = async function (params) {
    // console.log('333333333333333');
    const data = await productsModel.updateOne(params, { delete: true });
    return data;
}
//修改某个保险产品的数据
module.exports.modifyProducts = async function (params) {
    const data = await productsModel.updateOne({ _id: params._id }, params);
    return data;
}
//新增保险产品的数据
module.exports.addProducts = async function (params) {
    const data = await productsModel.create(params);
    console.log(data);
    return data;
}
//获取全部数据
module.exports.getProductsall = async function (params) {
    const data = await productsModel.find({ delete: false });
    return data;
}

